package myky.com.doctorapp.presenter;

import io.reactivex.disposables.Disposable;
import myky.com.doctorapp.entity.LoginSuccessEntity;
import myky.com.doctorapp.entity.SmsCodeEntity;
import myky.com.doctorapp.base.BasePresenterIm;
import myky.com.doctorapp.base.RxSubscribe;
import myky.com.doctorapp.contract.PnLoginFragmentContract;
import myky.com.doctorapp.model.PnLoginFragmentModel;

/**
 * Description:
 *
 * @author Mr.li
 * Ctreated by 2018/12/13 17:38
 */
public class PnLoginFragmentPresenter extends BasePresenterIm<PnLoginFragmentContract.View> implements PnLoginFragmentContract.Presenter {


    private PnLoginFragmentModel pnFragmentModel;

    public PnLoginFragmentPresenter() {
        pnFragmentModel = new PnLoginFragmentModel();
    }

    @Override
    public void quickLogin() {
        pnFragmentModel.quickLogin().subscribe(new RxSubscribe<LoginSuccessEntity.PayLoadBean>() {
            @Override
            protected void onSuccess(LoginSuccessEntity.PayLoadBean loginEntity) {
                mView.loginSuccess(loginEntity);
            }

            @Override
            protected void onFailed(int code, String msg) {
                mView.showDataError("登录失败");
            }

            @Override
            public void onSubscribe(Disposable d) {
                addSubscription(d);
            }
        });
    }

    @Override
    public void getSmsCode(String mobile, String opt) {
        pnFragmentModel.getSmsCode(mobile, opt).subscribe(new RxSubscribe<SmsCodeEntity.PayloadBean>() {
            @Override
            protected void onSuccess(SmsCodeEntity.PayloadBean loginEntity) {
                mView.showCode(loginEntity);
            }

            @Override
            protected void onFailed(int code, String msg) {
                mView.getCodeError(code);
            }

            @Override
            public void onSubscribe(Disposable d) {
                addSubscription(d);
            }
        });
    }

}
